package com.zhiche.lisa.bms.service.view.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.zhiche.lisa.bms.dao.mapper.view.FeePayablePriceMapper;
import com.zhiche.lisa.bms.dao.model.view.FeePayablePrice;
import com.zhiche.lisa.bms.service.view.FeePayablePriceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author linbao
 * @since 2019-03-04
 */
@Service
@Slf4j
public class FeePayablePriceServiceImpl extends ServiceImpl<FeePayablePriceMapper, FeePayablePrice> implements FeePayablePriceService {

    /**
     * 根据系统订单号获取对应的价格
     *
     * @param waybillId
     * @param typeName
     * @return
     */
    @Override
    public FeePayablePrice getFeePayablePriceByWaybillId(String waybillId, String typeName) {
        if (StringUtils.isNotBlank(waybillId)) {
            EntityWrapper<FeePayablePrice> ew = new EntityWrapper<>();
            ew.eq("waybill_dtl_id", waybillId);
            ew.eq("type_name", typeName);
            List<FeePayablePrice> feePayablePriceList = this.selectList(ew);
            if (CollectionUtils.isNotEmpty(feePayablePriceList)) {
                return feePayablePriceList.get(0);
            }
        }
        return null;
    }


    /**
     * 根据OR号获取信息
     *
     * @param waybillIdList
     * @param typeName
     * @return
     */
    @Override
    public Map<String, FeePayablePrice> getFeePayablePriceByWaybillId(List<String> waybillIdList, String typeName) {
        if (CollectionUtils.isNotEmpty(waybillIdList)) {
            EntityWrapper<FeePayablePrice> ew = new EntityWrapper<>();
            ew.in("waybill_dtl_id", waybillIdList);
            ew.eq("type_name", typeName);
            List<FeePayablePrice> feePayablePriceList = this.selectList(ew);
            Map<String, FeePayablePrice> resultMap = Maps.newHashMap();
            if (CollectionUtils.isNotEmpty(feePayablePriceList)) {
                feePayablePriceList.forEach(price -> {
                    resultMap.put(price.getWaybillDtlId(), price);
                });
            }
            return resultMap;
        }
        return null;
    }
}
